package com.joe.demo.netty;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;

/**
 * @Description
 * @Author gaojw
 * @Date 2024-08-29
 */
public class TestSlice {

    public static void main(String[] args) {
        final ByteBuf buffer = ByteBufAllocator.DEFAULT.buffer();
        buffer.writeBytes(new byte[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'});
        System.out.println(buffer);
        // 在切片过程中，没有发生数据复制， 对最大容量有限制
        final ByteBuf byteBuf = buffer.slice(2, 4);
        byteBuf.retain();
        byteBuf.release();

        System.out.println(byteBuf);

        buffer.release();
    }
}
